﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class ShopOnlineAdmin_ProductFeedback : SiteAdminBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string cmdText = "select a.*, b.NodeID FeedbackNodeID, b.Subject FeedbackSubject, b.CreateDate FeedbackCreateDate, "+
                "b.Username FeedbackUsername, b.IPAddress FeedbackIPAddress, b.FeedbackContent  "+
                "from T_Product a left join T_Feedback b on a.ProductID = b.Category where b.FeedbackContent is not null order by FeedbackCreateDate desc";
            FillGirdView(0, cmdText);
            //this.searchFree.InitData();
        }
        else
        {
            FillGirdView(this.gridView.SplitPageIndex, string.Empty);
        }
    }

    protected void FillGirdView(int currentPage, string cmdText)
    {
        if (string.IsNullOrEmpty(cmdText))
        {
            cmdText = ViewState[this.ClientID + "cmdText"].ToString();
        }
        ViewState[this.ClientID + "cmdText"] = cmdText;
        SplitPageAccess splitPage = new SplitPageAccess(base.Connection, cmdText);
        splitPage.PageSize = 10;
        DataSet ds = splitPage.LoadDataSet(currentPage);
        gridView.ShowFooter = true;
        gridView.NavigationData = splitPage.GetNavigationData(currentPage);
        gridView.DataSource = ds.Tables[0];
        gridView.DataBind();
    }

    public void searchFree_OnQueryData(SearchEventArgs e)
    {
        string cmdText = "select a.*, b.NodeID FeedbackNodeID, b.Subject FeedbackSubject, b.CreateDate FeedbackCreateDate, " +
            "b.Username FeedbackUsername, b.IPAddress FeedbackIPAddress, b.FeedbackContent  " +
            "from T_Product a left join T_Feedback b on a.ProductID = b.Category where b.FeedbackContent is not null {0} order by FeedbackCreateDate desc";

        if (e.FilterString != string.Empty)
        {
            cmdText = string.Format(cmdText, " and "+ e.FilterString);
        }
        else
        {
            cmdText = string.Format(cmdText, string.Empty);
        }
        FillGirdView(0, cmdText);
    }

    protected void gridView_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        try
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ((HyperLink)e.Row.Cells[2].Controls[0]).Text = base.FormatSubject(((HyperLink)e.Row.Cells[2].Controls[0]).Text, 20);
                e.Row.Cells[3].Text = BaseAccess.ExecuteScalar(base.Connection, "select Subject from T_ProductCategory where NodeID='" + e.Row.Cells[3].Text + "'");
                e.Row.Cells[5].Text = Convert.ToDateTime(e.Row.Cells[5].Text).ToString("yyyy-MM-dd");
                e.Row.Cells[6].Text = base.FormatZero(e.Row.Cells[6].Text);
                e.Row.Cells[7].Text = base.FormatZero(e.Row.Cells[7].Text);
                e.Row.Cells[8].Text = base.FormatZero(e.Row.Cells[8].Text);
                e.Row.Cells[11].Text = base.FormatBoolean(e.Row.Cells[11].Text, "是", "否");
                e.Row.Cells[12].Text = base.FormatBoolean(e.Row.Cells[12].Text, "是", "否");
            }
        }
        catch { }
    }

    protected void gridView_SplitPageIndexChange(object sender, CommandEventArgs e)
    {
        FillGirdView(Int32.Parse(e.CommandArgument.ToString()), ViewState[this.ClientID + "cmdText"].ToString());
    }

    protected void btnRemove_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(Request["FeedbackNodeID"]))
        {
            base.Alert("请选择一条记录");
            FillGirdView(this.gridView.SplitPageIndex, string.Empty);
            return;
        }

        string cmdText = "delete from T_Feedback where NodeID = '{0}'";
        BaseAccess.ExecuteNonQuery(base.Connection, string.Format(cmdText, Request["FeedbackNodeID"].Replace("'", string.Empty)));
        FillGirdView(this.gridView.SplitPageIndex, string.Empty);

    }
}
